******************************************************************************************
* Name: 	classify-office.do
* Purpose: 	This file classifies offices into broad categories
* note: CPA = Community Planning Area
*		MAC = Municipal Advisory Council
******************************************************************************************

******************
* First version
******************

	
	gen officecat$year = .

	replace officecat$year = 1 if strpos(office$year, "COUNTY SUPERVISOR")
	replace officecat$year = 2 if strpos(office$year, "MAYOR")
	replace officecat$year = 3 if strpos(office$year, "CITY COUNCIL") | /// 
								  strpos(office$year, "TOWN COUNCIL") | ///
								  strpos(office$year, "COUNTY COUNCIL") 
	replace officecat$year = 4 if strpos(office$year, "TREASURER") | ///
								  strpos(office$year, "CITY AUDITOR") | ///
								  strpos(office$year, "CITY ATTORNEY")  | ///
								  strpos(office$year, "CLERK") | ///
								  strpos(office$year, "ASSESSOR") | ///
								  strpos(office$year, "AUDITOR") | ///
								  strpos(office$year, "CONTROLLER") | ///
								  strpos(office$year, "TAX COLLECTOR")
	replace officecat$year = 5 if strpos(office$year, "BOARD MEMBER") | ///
								 strpos(office$year, "DIRECTOR") | ///
								 strpos(office$year, "SCHOOL BOARD") | ///
								 strpos(office$year, "SUPERINTENDENT") 
	replace officecat$year = 6 if strpos(office$year, "DISTRICT ATTORNEY") | ///
								  strpos(office$year, "JUDGE") | ///
								  strpos(office$year, "PUBLIC DEFENDER") | ///
								  strpos(office$year, "CITY PROSECUTOR")
	replace officecat$year = 7 if strpos(office$year, "RENT") | strpos(office$year, "CPA")
	replace officecat$year = 8 if strpos(office$year, "MARSHALL") | ///
								  strpos(office$year, "MARSHAL") | ///
								  strpos(office$year, "SHERIFF") | ///
								  strpos(office$year, "POLICE") | ///
								  strpos(office$year, "CORONER") | ///
								  strpos(office$year, "SHERRIFF")
	replace officecat$year = 9 if strpos(office$year, "MAC") | strpos(office$year, "ADVISORY COUNCIL")
	replace officecat$year = 9 if strpos(place$year, "CSD") & officecat$year==5

	label val officecat$year officecat	

	tab officecat$year if office$year!="", m
	tab office$year if officecat$year==., m 


*******************
* Second version 
*******************

* combine last four categories into an "other category"
	
	gen officecat2$year = .

	replace officecat2$year = 1 if strpos(office$year, "COUNTY SUPERVISOR")
	replace officecat2$year = 2 if strpos(office$year, "MAYOR")
	replace officecat2$year = 3 if strpos(office$year, "CITY COUNCIL") | ///
								   strpos(office$year, "TOWN COUNCIL") | ///
								   strpos(office$year, "COUNTY COUNCIL") 
	replace officecat2$year = 4 if strpos(office$year, "TREASURER") | ///
								   strpos(office$year, "CITY AUDITOR") | ///
								   strpos(office$year, "CITY ATTORNEY")  | ///
								   strpos(office$year, "CLERK") | ///
								   strpos(office$year, "ASSESSOR") | ///
								   strpos(office$year, "AUDITOR") | ///
								   strpos(office$year, "CONTROLLER") | ///
								   strpos(office$year, "TAX COLLECTOR")
	replace officecat2$year = 5 if strpos(office$year, "BOARD MEMBER") | ///
								   strpos(office$year, "DIRECTOR") | ///
								   strpos(office$year, "SCHOOL BOARD") | ///
								   strpos(office$year, "SUPERINTENDENT") 
	replace officecat2$year = 6 if strpos(office$year, "DISTRICT ATTORNEY") | ///
								   strpos(office$year, "JUDGE") | ///
								   strpos(office$year, "PUBLIC DEFENDER") | ///
								   strpos(office$year, "CITY PROSECUTOR") | ///
									strpos(office$year, "RENT") | ///
									strpos(office$year, "CPA") | ///
									strpos(office$year, "MARSHALL") | ///
									strpos(office$year, "MARSHAL") | ///
									strpos(office$year, "SHERIFF") | ///
									strpos(office$year, "POLICE") | ///
									strpos(office$year, "CORONER") | ///
									strpos(office$year, "MAC") | ///
									strpos(office$year, "ADVISORY COUNCIL") | ///
									strpos(office$year, "SHERRIFF")
	replace officecat2$year = 6 if strpos(place$year, "CSD") & officecat2$year==5

	label val officecat2$year officecat2	

	tab officecat2$year if office$year!="", m
	tab office$year if officecat2$year==., m 

